package com.ghsc.ghxc.jsb.ui.live.activity

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeListResponse
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.ext.loge
import com.cn.appcore.http.TypeConversion
import com.cn.appcore.http.bean.BaseListResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.home.bean.TasksStateResult
import com.ghsc.ghxc.jsb.ui.live.bean.FollowResult
import com.ghsc.ghxc.jsb.ui.live.bean.LiveSendRedResult
import com.ghsc.ghxc.jsb.ui.live.bean.LiveUserInfoResult
import com.ghsc.ghxc.jsb.ui.my.bean.LikeCollFollowResult
import com.ghsc.ghxc.jsb.ui.my.bean.OssTokenResultDataBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.live.activity
 * 类名：LiveViewModel
 * 创建时间：2024/5/10 15:43
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class LiveViewModel : BaseViewModel() {



    /**
     * 直播_房间信息
     */
    val onRoomInfoData: MutableLiveData<BaseResponse<FollowResult>> = MutableLiveData()
    fun onRoomInfoMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onRoomInfoData(paras) }
            executeResponse(
                response,
                { onRoomInfoData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }

    }

    /**  根据id列表查询用户 **/
    val onGetIdsListData: MutableLiveData<BaseResponse<LiveUserInfoResult>> = MutableLiveData()
    fun onGetIdsListMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGetIdsListData(paras) }
            executeResponse(
                response,
                { onGetIdsListData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }

    /** 阿里云oos **/
    var onAliYunOosData = MutableLiveData<BaseResponse<OssTokenResultDataBean>>()
    fun onAliYunOosMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onAliYunOosData(paras) }
            executeResponse(
                response,
                { onAliYunOosData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }

    /** 关注用户 **/
    val onUserFollowData: MutableLiveData<BaseResponse<LikeCollFollowResult>> = MutableLiveData()
    fun onUserFollowMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onUserFollowData(paras) }
            executeResponse(
                response,
                { onUserFollowData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }





    /** 查询是否有红包 **/
    val onGetLiveRedData: MutableLiveData<BaseResponse<LiveSendRedResult>> = MutableLiveData()
    fun onGetLiveRedMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGetLiveRedData(paras) }
            loge("是否有红包="+response.toString())
            executeResponse(
                response,
                { onGetLiveRedData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }
    /**
     *  抢红包
     */
    var onGetPacketSubmitData = MutableLiveData<BaseResponse<Any>>()
    fun onGetPacketSubmitMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGetPacketSubmitData(paras) }
            executeResponse(
                response,
                { onGetPacketSubmitData.value = response },
                { againLoginMsg.value = response.msg }
            ) { getRewardErrorData.value = response }
        }
    }

    /**
     * 获取日常任务
     */
    var onZbTaskListData = MutableLiveData<BaseListResponse<TasksStateResult>>()
    fun onZbTaskListMethod(json:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onZbTaskListData(json) }
            executeListResponse(
                response,
                { onZbTaskListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

    /**
     * 完成日常任务
     */
    var onZbFinishTaskData = MutableLiveData<BaseResponse<Any>>()
    fun onZbFinishTaskMethod(json:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onZbFinishTaskData(json) }
            executeListResponse(
                response,
                { onZbTaskListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }



}